package hiber;

import hiber.hbm.Collection;
import hiber.hbm.User;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateTest {

	public static void main(String[] args) {

		SessionFactory sessionFactory = new Configuration().configure()
				.buildSessionFactory();

		System.out.println("sessionFactory=" + sessionFactory);

		Session session = sessionFactory.openSession();

		session.beginTransaction();

		Collection collection = new Collection();
		collection.setFirstName("psd 3");
		session.save(collection);
		// session.delete(collection);

		// List<Collection> collections =
		// session.createQuery("from Collection").list();
		// for (Collection c : collections) {
		// System.out.println(c.getId() + " : " + c.getFirstName());
		// }

		User user = new User();
		user.setEmail("cororok@gmail.com");
		session.save(user);

		user.setEmail("cororok@yahoo.com");
		session.save(user);

		session.getTransaction().commit();

		session.close();

		System.out.println("end");

	}
}
